package com.hl.yyx.modules.ums.controller;

import com.hl.yyx.common.log.LogAnnotation;
import com.hl.yyx.common.response.ObjectResponse;
import com.hl.yyx.common.response.Response;
import com.hl.yyx.dto.IdDTO;
import com.hl.yyx.dto.SearchFilters;
import com.hl.yyx.modules.ums.dto.AuthMenuDTO;
import com.hl.yyx.modules.ums.model.UmsRole;
import com.hl.yyx.modules.ums.service.UmsRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author hl243695czyn
 * @since 2022-06-19
 */
@RestController
@Api(tags = "角色管理", description = "角色管理")
@RequestMapping("/admin/role")
public class UmsRoleController {

    @Autowired
    private UmsRoleService umsRoleService;

    // 分页
    @LogAnnotation()
    @ApiOperation("分页查询")
    @PostMapping(value = "/page")
    public Response page(@RequestBody SearchFilters<UmsRole> searchFilters) {
        return umsRoleService.pageList(searchFilters);
    }

    // 新增
    @LogAnnotation()
    @ApiOperation("新增角色")
    @PostMapping(value = "/create")
    public Response create(@Valid @RequestBody UmsRole umsRole) {
        return umsRoleService.create(umsRole);
    }

    // 更新
    @LogAnnotation()
    @ApiOperation("更新角色")
    @PostMapping(value = "/update")
    public Response update(@Valid @RequestBody UmsRole umsRole) {
        return umsRoleService.updateRole(umsRole);
    }

    // 删除
    @LogAnnotation()
    @ApiOperation("删除角色")
    @PostMapping(value = "/delete")
    public Response delete(@Valid @RequestBody IdDTO idDTO) {
        return umsRoleService.delete(idDTO);
    }

    // 获取全部
    @LogAnnotation()
    @ApiOperation("获取全部角色")
    @PostMapping(value = "/list")
    public Response list() {
        return new ObjectResponse<>(umsRoleService.list());
    }

    // 查看
    @LogAnnotation()
    @ApiOperation("查看角色")
    @PostMapping(value = "/view")
    public Response view(@Valid @RequestBody IdDTO idDTO) {
        return umsRoleService.view(idDTO);
    }


    // 获取角色已分配的权限
    @LogAnnotation()
    @ApiOperation("获取已分配的权限")
    @PostMapping(value = "/viewAuth")
    public Response viewAuth(@Valid @RequestBody IdDTO idDTO) {
        return umsRoleService.viewAuth(idDTO);
    }

    // 分配权限
    @LogAnnotation()
    @ApiOperation("分配权限")
    @PostMapping(value = "/auth")
    public Response authMenu(@Valid @RequestBody AuthMenuDTO authMenuDTO) {
        return umsRoleService.authMenu(authMenuDTO);
    }

}

